<?php

namespace App\Http\Controllers;

use App\Http\Model\GoodsTaobao;
use App\Http\Service\ExcelTaobao;
use Illuminate\Support\Facades\DB;

class HomeController extends Controller
{
    /**
     * Create a new controller instance.
     *
     * @return void
     */
    public function __construct()
    {
        //
    }

    function index(){
        $user = GoodsTaobao::all();
		return view('index');
	}
    function demo(){
		return view('demo');
	}
    function upload_excel(){
        ExcelTaobao::read_data(function($data){
            foreach ($data as $index=>$item){
                $goods_id = $item[0];
                $good = GoodsTaobao::where(["goods_id"=>$goods_id])->first();
                if(!$good){
                    $good = new GoodsTaobao;
                }
                $good->goods_id = $item[0];
                $good->goods_name = $item[1];
                $good->pic = $item[2];
                $good->main_url = $item[3];
                $good->cate = $item[4];
                $good->ad_url = $item[5];
                $good->goods_price = $item[6];
                $good->goods_sale_num = $item[7];
                $good->goods_extract = $item[8];
                $good->charge = $item[9];
                $good->wangwang = $item[10];
                $good->sellerId = $item[11];
                $good->shop_name = $item[12];
                $good->platform = $item[13];
                $good->coupon_id = $item[14];
                $good->coupon_total = $item[15];
                $good->coupon_surplus = $item[16];
                $good->coupon_value = $item[17];
                $good->begin = $item[18];
                $good->end = $item[19];
                $good->coupon_url = $item[20];
                $good->coupon_ad_url = $item[21];
                $good->save();
                echo "【 $index 】".  $good->goods_name."<br/>";
            }
        });
	}

}
